package impl;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class Audience {
    @Pointcut("execution(* services.Performance.perform(..))")
    public void performance() {

    }

//    @Before("performance()")
//    public void silenceCellPhone() {
//        System.out.println("silence cell phone");
//    }
//
//    @Before("performance()")
//    public void takeSeates() {
//        System.out.println("take Seates");
//    }
//
//    @AfterReturning("performance()")
//    public void applause() {
//        System.out.println("audience applause");
//    }
//
//    @AfterThrowing("performance()")
//    public void demandRefund() {
//        System.out.println("Demand a refund");
//    }

    @Around("performance()")
    public void watchPerformance(ProceedingJoinPoint joinPoint) {
        try {
            System.out.println("silence cell phone");
            System.out.println("take Seates");
            Object[] args = joinPoint.getArgs();
            Object[] argsChange = new Object[args.length];
            for(int i = 0; i < args.length; i++){
                if (args[i] instanceof String) {
                    argsChange[i] = "gai bian can shu";
                }
            }
            joinPoint.proceed(argsChange);
            System.out.println("audience applause");
        } catch (Throwable e) {
            System.out.println("Demand a refund");
        }
    }
}
